/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.modudf;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.UIManager;

public class Main extends JFrame {

    public Main() {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }

        MoveMouseListener mml = new MoveMouseListener(Main.this);
        addMouseListener(mml);
        addMouseMotionListener(mml);
        add(new MainPanel2(Main.this));
        setUndecorated(true);
        setSystemTray();
        setTitle("MODUDF -- JRE,Tomcat,MySQL");
        setIconImage(getToolkit().getImage(getClass().getResource("/com/modudf/resources/modudf_logo.png")));  
        Dimension ds = Toolkit.getDefaultToolkit().getScreenSize();
        pack();
        Dimension dw = getSize();
        setLocation((int) ((ds.getWidth() - dw.getWidth()) / 2),
                (int) ((ds.getHeight() - dw.getHeight()) / 2));
        setVisible(true);

    }

    private void setSystemTray() {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        SystemTray st = SystemTray.getSystemTray();
        Image i = toolkit.getImage(getClass().
                getResource("/com/modudf/resources/modudf.png"));
        TrayIcon ti = new TrayIcon(i);
        ti.setImageAutoSize(true);
        ti.setToolTip("MODUDF(jre,tomcat,mysql");
        ti.setPopupMenu(new MyPopupMenu(this));
        ti.addMouseListener(new TrayClick());
        try {
            st.add(ti);
        } catch (AWTException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main();
    }

    private class TrayClick extends MouseAdapter {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 1) {
                if (Main.this.isVisible()) {
                    Main.this.setVisible(false);
                } else {
                    Main.this.setVisible(true);
                }
            }
        }
    }
}
